package com.future.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.future.domain.Permission;
import com.future.domain.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    /**
     * 根据角色 ID 查询该角色拥有的权限列表
     * @param roleId 角色 ID
     * @return 权限列表
     */
    @Select("SELECT p.* FROM permission p " +
            "JOIN role_permission rp ON p.id = rp.permission_id " +
            "JOIN role r ON rp.role_id = r.id " +
            "WHERE r.id = #{roleId}")
    List<Permission> selectPermissionsByRoleId(@Param("roleId") Long roleId);
    /**
     * 根据用户 ID 查询该用户的角色列表
     * @param userId 用户 ID
     * @return 角色列表
     */
    @Select("SELECT r.* FROM role r " +
            "JOIN user_role ur ON r.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<Role> selectUserRolesByUserId(@Param("userId") Long userId);
}
